package com.android.lovingpet.community;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.android.lovingpet.common.postlist.PostListFragment;
import com.android.lovingpet.community.sift.SiftFragment;

public class PageAdapter extends FragmentPagerAdapter {

    private String[] titles = {"精选", "动态"};
    private SiftFragment siftFragment;
    private PostListFragment postListFragment;

    public PageAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 1) {
            if (postListFragment == null) {
                postListFragment = PostListFragment.newInstance(2, 5);
            }
            return postListFragment;
        }
        if (position == 0) {
            if (siftFragment == null) {
                siftFragment = new SiftFragment();
            }
            return siftFragment;
        }
        return null;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
